import os
# 计算代码行
for i in os.listdir('.'):  # 打开本地目录的文件
    if os.path.splitext(i)[1] == '.py':
        with open(i, 'rb') as f:
            code = 0  # 计算代码行
            notes = -1  # 计算注释行
            empty_line = 0  # 计算空白行
            for j in f.readlines():
                code += 1
                if len(j.strip()) == 0:
                    empty_line += 1
                if b'#' in j:
                    notes += 1
            print('代码总行数：', code)
            print('空白行总行数', empty_line)
            if notes == -1:
                notes = 0
            print('注释行总行数', notes)
